function loadOptionsByRepository(){
	$("#repositories").change(function(event){
		var selected = $("#repositories option:selected").text();
		if (selected == 'VERSION REPOSITORY' || selected == 'TRACKER REPOSITORY'){
			Options.getOptionsByRepository(selected, updateOptions);
		} else {
			emptyOptions("metrics");
			emptyOptions("types");
			emptyOptions("status");
		}
	});
}

function updateOptions(data){
	updateSelect("metrics", data[0]);
	updateSelect("types", data[1]);
	updateSelect("status", data[2]);
}

function loadMetricsByRepository(){
	$("#repositoriesReport").change(function(event){
		var selected = $("#repositoriesReport option:selected").text();
		if (selected == 'VERSION REPOSITORY' || selected == 'TRACKER REPOSITORY'){
			Options.getOptionsByRepository(selected, updateMetrics);
		} else {
			emptyOptions("metricsReport");
		}
	});
}

function updateMetrics(data){
	updateSelect("metricsReport", data[0]);
}

function updateSelect(selectId, data){
	var elem = $("#" + selectId);
	emptyOptions(selectId);
	
	var option = data.split("%%");
	for (var i = 0; i < option.length - 1; i++) {
		var parameters = option[i].split("##");
		elem.append($("<option>").attr("value", parameters[0]).text(parameters[1]));
	}
}

function emptyOptions(elemId){
	var elem = $("#" + elemId);
	elem.empty();
	elem.append($("<option>").attr("selected", true).text("--Select an Option--"));
}